using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using QLNS.Data;
using QLNS.Object;
using System.Data;


namespace QLNS.Control
{
    class HeSoLuongCtrl
    {
        HeSoLuongData data = new HeSoLuongData();        
        
        BindingSource bs = new BindingSource();
        public void HienthiHeSoLuongDataGridview(DataGridView dg, BindingNavigator bn)
        {
            BindingSource bs = new BindingSource();
            DataTable tbl = data.DanhSachHeSoLuong();
            bs.DataSource = tbl;
            bn.BindingSource = bs;
            dg.DataSource = bs;

        }

        public void HienthiHeSoLuongDataGridview(System.Windows.Forms.DataGridView dg, System.Windows.Forms.BindingNavigator bn,
            ComboBox cmbNgach,TextBox txtMaNgach, TextBox txtTenNgach)
        {
            System.Windows.Forms.BindingSource bs = new System.Windows.Forms.BindingSource();
            bs.DataSource = data.DanhSachHeSoLuong();

            cmbNgach.DataBindings.Clear();
            cmbNgach.DataBindings.Add("SelectedValue",bs,"Ngach");

            txtMaNgach.DataBindings.Clear();
            txtMaNgach.DataBindings.Add("Text", bs, "BacLuong");

            txtTenNgach.DataBindings.Clear();
            txtTenNgach.DataBindings.Add("Text", bs, "HeSoLuong");

            bn.BindingSource = bs;
            dg.DataSource = bs;
        }
        public IList<HeSoLuongInfo> LayDanhSachHeSoLuong()
        {
            DataTable tbl = data.DanhSachHeSoLuong();
            IList<HeSoLuongInfo> ds = new List<HeSoLuongInfo>();

            foreach (DataRow row in tbl.Rows)
            {
                HeSoLuongInfo hsl = new HeSoLuongInfo();
                hsl.Ngach = Convert.ToString(row["Ngach"]);
                hsl.BacLuong = Convert.ToString(row["BacLuong"]);
                hsl.BacLuong = Convert.ToString(row["HeSoLuong"]);
                ds.Add(hsl);
            }
            return ds;
        }
        public void HienthiDataGridview(DataGridView dg, BindingNavigator bn, ComboBox cmbNgach,
              ComboBox cmbBacLuong, ComboBox cmbHeSoLuong )
        {
            bs.DataSource = data.DanhSachHeSoLuong();
            cmbNgach.DataBindings.Clear();
            cmbNgach.DataBindings.Add("SelectedValue", bs, "Ngach");            

            cmbBacLuong.DataBindings.Clear();
            cmbBacLuong.DataBindings.Add("SelectedValue", bs, "BacLuong");            

            cmbHeSoLuong.DataBindings.Clear();
            cmbHeSoLuong.DataBindings.Add("SelectedValue", bs, "HeSoLuong");
           
            bn.BindingSource = bs;
            dg.DataSource = bs;
        }
        public DataTable LayHeSoLuong(string ngach, string bac)
        {
            return data.LayHeSoLuong(ngach,bac);
        }
        public string TimMa(String ma)
        {
            data.TimMa(ma);
            if (data != null)
                return ma;
            return null;
        }
        public double TimHeSo(double heso)
        {
            data.TimHeSo(heso);
            if (data != null)
                return heso;
            return 0;
        }

        public DataRow NewRow()
        {
            return data.NewRow();
        }
        public void Add(DataRow row)
        {
            data.Add(row);
        }
        public bool Save()
        {
            return data.Save();
        }
        public void Update()
        {
            bs.MoveNext();
            data.Save();
        }
    }
}
